/*eslint no-console:0 */
import axios from 'axios'
import qs from 'qs'

const service = axios.create({
  baseURL: process.env.VUE_APP_BASE_API,
  // baseURL: 'http://api.unmcc.com',
  validateStatus: status => {
    return status < 500
  }
})

service.interceptors.request.use(
  config => {
    config.data = qs.stringify(config.data)
    return config
  },
  error => {
    console.log(error)
    return Promise.reject(error)
  }
)

service.interceptors.response.use(
  response => {
    // console.log(response)
    const { data: res } = response

    return res
  },
  error => {
    console.log(error)
    return Promise.reject(error)
  }
)

export default service
